<template>
  <div>
<!-- 编辑性别 -->
<van-picker
  title="标题"
  show-toolbar
  :columns="columns"
  :default-index="value"
  @confirm="onConfirm"
  @cancel="$emit('close')"
/>
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  name: 'UserEditsex',
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      columns: ['男', '女']
    }
  },

  created () {

  },

  methods: {
    async onConfirm (val, index) {
      Toast.loading({
        message: '发布中...',
        duration: 0,
        forbidClick: true
      })
      console.log('点击确认')
      try {
        await updateUserProfile({
          gender: index
        })
        Toast.success('确认更新成功')
        this.$emit('close')
        this.$emit('input', index)// 改性别刷新后还会固定
      } catch (error) {
        Toast.fail('确认更新失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
